package com.yiming.shiro.controller;

import com.yiming.shiro.controller.vo.UserVO;
import com.yiming.shiro.service.UserService;
import com.yiming.shiro.service.dto.UserDTO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
public class BusinessController {

    @Autowired
    private UserService userService;

    @RequiresRoles(value = {"manager"})
    @RequiresPermissions(value = {"read_all"})
    @GetMapping(path = "/user/all")
    public List<UserVO> getUserInfoList() {
        List<UserDTO> allUsers = userService.getAllValidUsers();
        return allUsers.stream().map(userDTO -> UserVO.builder().name(userDTO.getName()).build()).collect(Collectors.toList());
    }
}
